package com.ruoyi.web.controller.biz;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.BsJingqu;
import com.ruoyi.system.service.BsJingquService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 说明 :
 */
@RestController
@Api(tags = "游客端-智能搜索")
@RequestMapping("/bs/intelligentSearch")
@Slf4j
public class BsIntelligentSearchController extends BaseController {

    @Resource
    private BsJingquService bsJingquService;

    @ApiOperation(value = "周边热搜", tags = {"游客端-智能搜索"})
    @GetMapping("/hotList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页,本接口默认1"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数,本接口默认5"),
    })
    public TableDataInfo<BsJingqu> hotList(@RequestParam(required = false) Integer pageNum, @RequestParam(required = false) Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        LambdaQueryWrapper<BsJingqu> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BsJingqu::getDelFlag, Constants.LOGIC_NOT_DELETE);
        lqw.orderByDesc(BsJingqu::getOrderNum);
        startPage(pageNum, pageSize);
        List<BsJingqu> list = bsJingquService.list(lqw);
        return getDataTable(list);
    }

    @ApiOperation(value = "异步累计搜索命中次数", tags = {"游客端-智能搜索"})
    @GetMapping("/asyncAppendOrderNum")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jingquId", value = "景区id"),
    })
    public Result<?> asyncAppendOrderNum(@RequestParam(required = false) String jingquId) {
        if (StrUtil.isNotBlank(jingquId)) {
            bsJingquService.runAsyncAppendOrderNum(jingquId);
        }
        return Result.success();
    }
}
